<!DOCTYPE html SYSTEM "http://www.thymeleaf.org/dtd/xhtml1-strict-thymeleaf-spring4-4.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xmlns:th="http://www.thymeleaf.org">
<html >
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1" />
    <title>HappyOJ</title>
    <meta http-equiv="pragma" content="no-cache">
    <link rel="stylesheet" href="css/styles.css" >
    <link rel="stylesheet" th:href="@{/js/editormd/css/editormd.css}" />
    <script src="js/jquery-1.7.2.js"></script>
    <script src="js/gdoj.js"></script>
</head>
<body>
<div th:replace="common::web-navbar"></div>
<div class="container">
    <div class="content">
        <div class="content-with-sidebar">
            <div th:replace="admin/admin-common::admin-navbar"></div>
            <div class="roundbox">
                <div class="home-edit-box comment" style="position: relative;padding: 6px;">
                    <form action="" method="post">
                        <H5><span>Home Page</span></H5>
                        <div class="editor-md-home" id="editor-md-home">
                            <textarea style="display:none;" id="editor-home-content" name="home-content"></textarea>
                        </div>
                        <H5><span>Sidebar</span></H5>
                        <div class="editor-md-sidebar" id="editor-md-sidebar">
                            <textarea style="display:none;" id="editor-sidebar-content" name="sidebar-content"></textarea>
                        </div>
                        <H5><span>Footer description</span></H5>
                        <div class="editor-md-footer" id="editor-md-footer">
                            <textarea class="ke-editor" style="width: 99%;" id="editor-footer-content" name="footer-content"></textarea>
                        </div>
                        <div style="margin-top: 12px;">
                            <input class="button_submit" type="submit" th:value="#{topic.btn_post}" >
                            <span class="fielderror"></span>
                        </div>
                    </form>
                </div>
            </div>
        </div>
        <div class="sidebar" th:replace="sidebar::web-sidebar"></div>
    </div>
    <div th:replace="common::web-footer"></div>
</div>
<script th:src='@{/js/kindeditor/kindeditor-all.js}' charset='utf-8'></script>
<script th:src='@{/js/editor.js}'></script>
<script th:src="@{/js/editormd/editormd.min.js}"></script>
<script type='text/javascript' th:src='@{/js/editor-md.js}'></script>
<script type="text/javascript">
    $(document).ready(function () {
        $.get('upload/maker/home-page.md', function(md) {
            $('#editor-home-content').val(md);
        });
        $.get('upload/maker/sidebar-top.md', function(md) {
            $('#editor-sidebar-content').val(md);
        });
        $.get('upload/maker/footer-desc.md', function(md) {
            $('#editor-footer-content').val(md);
        });
        EditorMarkDown.createEditorMD("editor-md-home");
        EditorMarkDown.createEditorMD("editor-md-sidebar");

        var formSubmitListener = function () {
            var contentHome = $(this).find("textarea[name=home-content]").val();
            var contentFooter = $(this).find("textarea[name=footer-content]").val();
            var contentSidebar = $(this).find("textarea[name=sidebar-content]").val();
            postContent = function () {
                $.post("/api/admin/homemaker",{ contentHome: contentHome, contentFooter: contentFooter,
                        contentSidebar:contentSidebar},
                    function (data) {
                        if (data.code != 200) {
                            $(".fielderror").html(data.msg);
                            $("#reply-content").focus();
                            return;
                        }

                        $('input[type=submit]', this).attr('disabled', 'disabled');
                        $('.button_submit').attr('disabled', 'disabled');
                        window.location.href="/admin";
                    },
                    "json"
                );
            };
            postContent();
            return false;
        }
        $(".home-edit-box").find("form").submit(formSubmitListener);
    });
</script>

</body>
</html>
